package com.smarth.zhizulian.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.smarth.zhizulian.R;
import com.smarth.zhizulian.app.BaseConfig;
import com.smarth.zhizulian.app.EventActivity;
import com.smarth.zhizulian.bean.cash.CashIsFirstCash;
import com.smarth.zhizulian.entity.EventBean;
import com.smarth.zhizulian.http.KumaHttp;
import com.smarth.zhizulian.http.observer.PageObserver;
import com.smarth.zhizulian.http.utils.RxCompos;
import com.smarth.zhizulian.utils.listhelper.impl.adapter.PageDataAdapter;
import com.smarth.zhizulian.utils.listhelper.impl.model.HttpPageDataModel;
import com.smarth.zhizulian.utils.listhelper.impl.model.PageDataModel;
import com.smarth.zhizulian.utils.listhelper.RefreshHelper;
import com.smarth.zhizulian.utils.listhelper.inter.ResponseSender;
import com.smarth.zhizulian.view.LoadingLayout;

import org.simple.eventbus.Subscriber;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observable;

/**
 * Created by 18865 on 2018/1/9.
 */

public class GetMoneyCenterActivity extends EventActivity {
    @BindView(R.id.tv_wechat)
    TextView tvWechat;
    @BindView(R.id.iv_wechat_arrow)
    ImageView ivWechatArrow;
    @BindView(R.id.rl_wechat)
    RelativeLayout rlWechat;
    @BindView(R.id.ll_loadinglayout)
    LoadingLayout llLoadinglayout;
    @BindView(R.id.tv_left)
    TextView tvLeft;
    private RefreshHelper<CashIsFirstCash> refreshHelper;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_getmoneycenter);
        ButterKnife.bind(this);
        setTitlebar("提现中心", true);
        init();
    }

    @OnClick({R.id.rl_moneydetail, R.id.rl_wechat, R.id.tv_contactservice})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_moneydetail:
                MoneyDetailActivity.open(mContext);
                break;
            case R.id.rl_wechat:
                GetMoneyActivity.open(mContext);
                break;
            case R.id.tv_contactservice:
                AboutUsActivity.open(mContext);
                break;
        }
    }

    public static void open(Context context) {
        Intent i = new Intent(context, GetMoneyCenterActivity.class);
        context.startActivity(i);
    }

    @Subscriber(tag = BaseConfig.EventTag.ON_GETMONEY)
    private void onGetMoney(EventBean eb) {
        refreshHelper.loadMore();
    }

    private void init() {
        refreshHelper = new RefreshHelper<CashIsFirstCash>(mContext, llLoadinglayout, null);
        refreshHelper.setDataModel(new HttpPageDataModel<CashIsFirstCash>(mContext) {
            @Override
            public Observable<CashIsFirstCash> getObservable() {
                return KumaHttp.getService().cashIsFirstCash()
                        .compose(RxCompos.<CashIsFirstCash>getBELoginCompos());
            }
        });
        refreshHelper.setDataAdapter(new PageDataAdapter<CashIsFirstCash>() {
            @Override
            public void onGetData(CashIsFirstCash cashIsFirstCash, boolean isRefresh) {
                super.onGetData(cashIsFirstCash, isRefresh);
                tvLeft.setText(cashIsFirstCash.getMoeny() + "元");
            }
        });
        refreshHelper.refresh();
    }
}
